package com.xq.controller;


import com.xq.apis.UmsUsersRolesApis;
import com.xq.constants.ErrorCodeConstants;
import com.xq.service.IUmsUserRolesService;
import com.xq.vo.JsonVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wuven
 * @since 2025-05-23
 */
@Api(tags = "角色管理")
@RestController
@RequestMapping("/ums-user-roles")
public class UmsUserRolesController implements UmsUsersRolesApis {

    @Autowired
    private IUmsUserRolesService umsUserRolesService;

    @PostMapping("/set-user-roles")
    @ApiOperation("分配用户角色")
    @Override
    public JsonVO<String> setUserRoles(@Parameter(name = "用户id") @RequestParam String userId,@Parameter(name = "角色名") @RequestParam String roleName) {
        umsUserRolesService.insertUserRoles(userId, roleName);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @GetMapping("/get-user-roles")
    @ApiOperation("获得用户角色（根据用户id）")
    @Override
    public JsonVO<List<String>> getUserRoles(@RequestParam String userId) {
        List<String> list = umsUserRolesService.listUserRoles(userId);
        return JsonVO.success(list);
    }

    @DeleteMapping("/delete-user-roles")
    @ApiOperation("删除用户角色（根据用户id以及角色名）")
    @Override
    public JsonVO<String> deleteUserRoles(@RequestParam String userId,@RequestParam String roleName) {
        umsUserRolesService.deleteUserRoles(userId, roleName);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }
}
